﻿using HPITSSBLL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HPITSSModel;


namespace HPITSSDAL
{
   public class LoginDAL
    {
        public static UserInfo GetUserInfoByNameandPwd(string name, string pwd)
        {
            string sql = "select * from [User] where Account=@Account and Password=@Password";
            SqlParameter[] pams= new SqlParameter[]
                {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                new SqlParameter("@Account",name),
                new SqlParameter("@Password",pwd)
                };

            SqlDataReader reader = DBHelper.ExecuteReader(sql, pams);
            reader.Read();
            List<UserInfo> list = new List<UserInfo>();
            while (reader.Read())
            {
                UserInfo u = new UserInfo
                {
                    UserName = reader["UserName"].ToString(),
                    Password = reader["Password"].ToString()
                };

                list.Add(u);
            }                
            reader.Close();
            if (list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }
        }

    }
}
